package com.bobo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bobo.domain.SysRoleMenu;
import com.bobo.service.SysRoleMenuService;
import com.bobo.mapper.SysRoleMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author THINKAPD
* @description 针对表【sys_role_menu】的数据库操作Service实现
* @createDate 2022-11-18 10:50:54
*/
@Transactional
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
    implements SysRoleMenuService{
    @Autowired
    SysRoleMenuMapper SysRoleMenuMapper;

    @Override
    public boolean bindMenu(SysRoleMenu sysRoleMenu) {

        //1 先删除该角色拥有的菜单
        LambdaQueryWrapper<SysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysRoleMenu::getRid,sysRoleMenu.getRid());
        this.remove(wrapper);
      ///  int i=10/0;
        //2.添加角色菜单
        Integer[] mids = sysRoleMenu.getMids();
        if(null!=mids &&mids.length>0){
            for (Integer mid : mids) {
                SysRoleMenu roleMenu = new SysRoleMenu();
                roleMenu.setRid(sysRoleMenu.getRid());
                roleMenu.setMid(mid);
              this.save(roleMenu);
            }
        }

        return true;
    }
}




